#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,t;
ll a[10010],b[10010],ans;
void dfs(int dep,ll summ)
{
    if(dep==n+1)
    {
        ans=max(ans,summ);
        return ;
    }
    if(dep==1)
    {
        b[dep]=1;
        dfs(dep+1,0);
        b[dep]=0;
        dfs(dep+1,0);
        return ;
    }
    ll blue=0,red=0;
    b[dep]=2;
    for(int i=dep;i>=1;i--)
    {
        if(b[i]==1)
        {
            if(a[i]==a[dep])blue=a[i];
            break;
        }
    }
    b[dep]=1;
    dfs(dep+1,summ+blue);
    b[dep]=2;
    for(int i=dep;i>=1;i--)
    {
        if(b[i]==0)
        {
            if(a[i]==a[dep])red=a[i];
            break;
        }
    }
    b[dep]=0;
    dfs(dep+1,summ+red);
    
    return ;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--)
    {
        ans=0;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        dfs(1,0);
        cout<<ans<<endl;
    }
    return 0;
}